package com.paraz.cst.impl;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

import com.paraz.cst.CstException;
import com.paraz.cst.CstOutput;

public class RealCstOutput implements CstOutput {

	private final Writer writer;
	
	RealCstOutput(RealCstSocket socket) {
		OutputStream outputStream;
		try {
			outputStream = socket.getSocket().getOutputStream();
		} catch (IOException e) {
			throw new IllegalStateException("could not set up outputStream", e);
		}
		writer = new OutputStreamWriter(outputStream);
	}
	
	public void write(String output) throws CstException {
		try {
			// flush() is needed to write immediately.
			writer.write(output);
			writer.flush();
		} catch (IOException e) {
			throw new CstException(e);
		}
	

	}

}
